#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

void Swap(int* a, int* b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}


void SelectInsert(int* a, int n)
{
	int left = 0;
	int right = n - 1;
	while (left < right)
	{
		int minx = left;
		int maxi = right;
		for (int i = left+1; i <= right; i++)
		{
			if (a[minx] > a[i])
			{
				minx = i;
			}
			if (a[maxi] < a[i])
			{
				maxi = i;
			}
		}
		if (maxi != left)
		{
			Swap(&a[left], &a[minx]);
			Swap(&a[right], &a[maxi]);
		}
		else
		{
			Swap(&a[left], &a[minx]);
		}

		left++;
		right--;
	}
}

void MyPrintf(int* a, int n)
{
	for (int i= 0; i < n; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}

int main()
{

	int a[] = { 1,4,7,983,5,-1,2,-5,-9,-10 };
	SelectInsert(a, sizeof(a) / sizeof(int));
	MyPrintf(a, sizeof(a) / sizeof(int));
	return 0;
}